<?php

require_once 'statics.php';
/*mysql_connect("db424304376.db.1and1.com", "dbo424304376", "2v_7z8sdi!h") or die(mysql_error());
mysql_select_db("db424304376") or die(mysql_error());*/
 $sql=mysql_connect("localhost","root","") or die(mysql_error());
  mysql_select_db("mydb",$sql) or die(mysql_error()); 



function get_memberID($email) {
    $id = mysql_query("SELECT member_id FROM member WHERE email = '$email'") or die("akeed hena" . mysql_error());
    $row = mysql_fetch_assoc($id);
    $i = $row['member_id'];
    return $i;
}

function get_email_byId($id) {
    $id = mysql_query("SELECT email FROM member WHERE member_id = $id") or die(mysql_error());
    $row = mysql_fetch_assoc($id);
    $i = $row['email'];
    return $i;
}

function get_reviewDeadline($confID) {
    $deadline = mysql_query("SELECT rev_endDate FROM conference WHERE
        conference_id = $confID") or die(mysql_error());
    while ($row = mysql_fetch_assoc($deadline)) {
        return $row['rev_endDate'];
    }
}

function get_user_name($id) {
    $name = mysql_query("SELECT first_name, last_name FROM member
      WHERE member_id = $id") or die(mysql_error());
    if (mysql_num_rows($name) == 1) {
        while ($n = mysql_fetch_assoc($name)) {
            $f = $n['first_name'];
            $l = $n['last_name'];
            return $f + " " + $l;
        }
    }
}

function createRandomPassword() {
    $chars = "abcdefghijkmnopqrstuvwxyz0123456789";
    srand((double) microtime() * 1000000);
    $i = 0;
    $pass = '';
    while ($i <= 7) {
        $num = rand() % 33;
        $tmp = substr($chars, $num, 1);
        $pass = $pass . $tmp;
        $i++;
    }
    return $pass;
}

function get_paper_title($paper_id) {
    $get_title = (mysql_query("select paper_title From paper Where paper_id = '$paper_id'")) or die(mysql_error());
    $row = mysql_fetch_assoc($get_title);
    $title = $row['paper_title'];
    return $title;
}

function get_conference_name($conference_id) {
    $get_name = (mysql_query("select long_name From conference Where conference_id = '$conference_id'")) or die(mysql_error());
    $row = mysql_fetch_assoc($get_name);
    $name = $row['long_name'];
    return $name;
}

function get_latest_version($paper_id) {
    $Latest_Version = mysql_query("SELECT version_id
                FROM version WHERE paper_id = '$paper_id' ORDER BY version_id DESC");
    $row = mysql_fetch_assoc($Latest_Version);
    $version = $row['version_id'];
    return $version;
}

function get_role($member_id, $conference_id) {
    $get_role = (mysql_query("Select role From member_privileges m , privileges p Where m.privileges_id =p.privileges_id AND m.member_id = '$member_id' AND m.conference_id='$conference_id'")) or (mysql_error());
    $row = mysql_fetch_assoc($get_role);
    $role = $row['role'];
    return $role;
}

function get_first_name($member_id) {
    $get_first_name = (mysql_query("Select first_name From member Where member_id = '$member_id'")) or (mysql_error());
    $row = mysql_fetch_assoc($get_first_name);
    $first_name = $row['first_name'];
    return $first_name;
}

function get_last_name($member_id) {
    $get_last_name = (mysql_query("Select last_name From member Where member_id = '$member_id'")) or (mysql_error());
    $row = mysql_fetch_assoc($get_last_name);
    $last_name = $row['last_name'];
    return $last_name;
}

function mysql_safe($variable) {
    $variable = mysql_real_escape_string(trim($variable));
    return $variable;
}

function formatText_safe($txt) {
    return htmlentities($txt);
}

?>
